package com.teach.servlet.admin;

import com.teach.dao.SportingEventsDAO;
import com.teach.dao.impl.SportingEventsDAOImpl;
import com.teach.entity.SportingEvents;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * -
 * 当前的项目名：medal-2022
 *
 * @author ZT
 * @data 2022/5/7 15:45
 **/
@WebServlet("/admin/SportingEvents-add.let")
public class SportingEventsAddServlet extends HttpServlet {

    private SportingEventsDAO dao = new SportingEventsDAOImpl();
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.reset();
        response.setContentType("application/json;charset=UTF-8");
        try {
            SportingEvents e = new SportingEvents();
            String seName = request.getParameter("seName");
            if (seName == null || "".equals(seName)) {
                throw new ServletException("体育项目名称不能为空");
            }
           /* String seDesc = request.getParameter("seDesc");
            if(seDesc == null || "".equals(seDesc)){
                throw new ServletException("seDesc不能为空！");
            }*/
//            String seId = request.getParameter("seId");
//            if (seId == null || "".equals(seId)) {
//                seId=null;
//            }
            e.setSeId(null);
            e.setSeName(request.getParameter("seName"));
            e.setSeDesc(request.getParameter("seDesc"));
            try {
                dao.insert(e);
                response.getWriter().print("{\"ok\":true}");
            } catch (Exception ex) {

            }

        }catch (Exception ex){
            response.getWriter().print("{\"ok\":false,\"msg\":\""+ex.getMessage()+"\"}");
        }

        response.flushBuffer();
    }

}
